﻿using Axgregn6Lib;
using gregn6Lib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Hotel.Reports.Controls
{
    public partial class ReportControl : UserControl
    {
        private GridppReport Report = new GridppReport();
        public ReportControl()
        {
            InitializeComponent();
            reportViewer.ShowToolbar = true;
        }

        public void Show(string fileName, string connectionString = "")
        {
            try
            {
                reportViewer.Stop();
                Report.Clear();
                //载入报表模板文件，必须保证 Grid++Report 的安装目录在‘C:\Grid++Report 6’下，
                //关于动态设置报表路径与数据绑定参数请参考其它例子程序
                //Report.LoadFromFile(@"C:\Grid++Report 6\Samples\Reports\1a.简单表格.grf");
                //Report.DetailGrid.Recordset.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
                //    @"User ID=Admin;Data Source=C:\Grid++Report 6\\Samples\Data\Northwind.mdb";
                Report.LoadFromFile(fileName);
                if (!string.IsNullOrEmpty(connectionString))
                {
                    Report.DetailGrid.Recordset.ConnectionString = connectionString;
                }
                //设置报表查询显示器控件的关联报表对象
                reportViewer.Report = Report;

                //启动报表运行
                reportViewer.Start();

            }
            catch (System.Exception ex)
            {
#if DEBUG
                Debug.WriteLine("报表加载出错:" + ex.Message);
                throw ex;
#endif
            } 
        }
        //public new void Dispose()
        //{            
        //    base.Dispose();
        //}
        ~ReportControl()
        {
            reportViewer?.Stop();
        }

        public new void Dispose()
        {
            //reportViewer?.Stop();
            base.Dispose();
        }
    }
}
